﻿<r:RibbonWindow x:Class="eComic" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:extbehaviour="clr-namespace:WPFExtensions.AttachedBehaviours;assembly=WPFExtensions"
                xmlns:local="clr-namespace:eComic" xmlns:wpe="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions" 
                xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary" 
                Title="eComic - Sequential Image Viewer" FontFamily="Arial" Background="White"
                ResizeMode="CanResizeWithGrip"  Width="875" Height="800" AllowDrop="True"
                Icon="/eComic;component/Resources/ecomic_icon.ico" IconVisibility="Collapsed"  >
    <r:RibbonWindow.Resources>
        <ResourceDictionary>
            <Style x:Key="PageListBoxStyle" TargetType="{x:Type ListBox}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBox}">
                            <Border Background="{TemplateBinding Panel.Background}"
								    BorderBrush="{TemplateBinding Border.BorderBrush}"
								    BorderThickness="{TemplateBinding Border.BorderThickness}">
                                <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible" 
                                              Template="{DynamicResource ScrollViewerControlTemplate1}">
                                    <local:eComicVirtualizingStackPanel IsItemsHost="True" Orientation="Vertical"/>
                                </ScrollViewer>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <r:RibbonCommand 
                x:Key="OpenCommand"
                Executed="OnOpenCommand"
                LabelTitle="Open"
                ToolTipTitle="Open An Existing Archive"
                ToolTipDescription="Opens an existing archive for viewing"                
                LargeImageSource="Resources/open32.png" 
                SmallImageSource="/eComic;component/Resources/open16.gif" />
            <r:RibbonCommand 
                x:Key="ResumeReadingKey"
                Executed="ReloadArchive"
                LabelTitle="Resume Reading"
                ToolTipTitle="Resume Reading"
                ToolTipDescription="Reloads the last Comic Archive that was loaded."
                SmallImageSource="Resources/reload24.png"
                LargeImageSource="Resources/reload.png"
                />
            <r:RibbonCommand 
                x:Key="PreviousArchive"
                x:Name="PreviousArchive"
                CanExecute="PreviousNextArchive_CanExecute" 
                Executed="OnPreviousArchive"
                LabelTitle="Load Previous Archive"
                ToolTipTitle="Load Previous Archive"
                ToolTipDescription="Loads the previous Archive"
                SmallImageSource="Resources/previous24.png"
                LargeImageSource="Resources/previous.png"
                />
            <r:RibbonCommand 
                x:Key="NextArchive"
                Executed="OnNextArchive"
                CanExecute="PreviousNextArchive_CanExecute" 
                LabelTitle="Load Next Archive"
                ToolTipTitle="Load Next Archive"
                ToolTipDescription="Loads the next Archive"
                SmallImageSource="Resources/next24.png"
                LargeImageSource="Resources/next.png"
                />
            <r:RibbonCommand 
                x:Key="ExitApplicationCommand"
                Executed="AppCommandCloseExecuted"
                LabelTitle="Exit"
                SmallImageSource="Resources/exit21.png"
                LargeImageSource="Resources/exit64.png"
                />
            <r:RibbonCommand x:Key="GotoPageCommand" x:Name="GotoPage" CanExecute="GotoPage_CanExecute" 
                             Executed="GotoPage_Executed" LabelTitle="Goto Page"
                             SmallImageSource="Resources/GoToPictureDocument24.png" LargeImageSource="Resources/GoToPictureDocument.png"
                             />
            <r:RibbonCommand x:Key="FileControls" x:Name="FileControls"
                             LabelTitle="File Controls" 
                             CanExecute="PreviousNextArchive_CanExecute" 
                             SmallImageSource="Resources/compass-icon21.png" LargeImageSource="Resources/compass-icon.png"
                             />
        </ResourceDictionary>
    </r:RibbonWindow.Resources>
    <DockPanel MouseWheel="page_MouseWheel" >
        <r:Ribbon DockPanel.Dock="Top" IsMinimized="true" 
                  Name="ribbonMenu" Title="eComic - Sequential Image Viewer">
            <r:Ribbon.ApplicationMenu>                
                <r:RibbonApplicationMenu>
                    <r:RibbonApplicationMenu.Footer>
                        <DockPanel LastChildFill="False" >
                            <r:RibbonButton Name="rbtnExit" Command="{StaticResource ExitApplicationCommand}"
                                            DockPanel.Dock="Right" />
                        </DockPanel>
                    </r:RibbonApplicationMenu.Footer>
                    <r:RibbonApplicationMenu.RecentItemList>
                        <HeaderedContentControl>
                            <HeaderedContentControl.Header>
                                <StackPanel Orientation="Vertical" >
                                    <Label Content="Recently Viewed Files" FontWeight="Bold" />    
                                    <Separator />
                                </StackPanel>                                
                            </HeaderedContentControl.Header>
                            <r:RibbonHighlightingList MostRecentFileSelected="mruList_MostRecentFileSelected" 
                                                  DisplayMemberPath="Name" Name="mruList" ItemsSource="{Binding MRU}"
                                                  />
                        </HeaderedContentControl>
                    </r:RibbonApplicationMenu.RecentItemList>
                    <r:RibbonApplicationMenu.Command>
                        <r:RibbonCommand LabelTitle="Application Button"
                                         LabelDescription="Close the application."
                                         LargeImageSource="resources/ecomic_icon-001.png"
                                         ToolTipTitle="eComic-Sequential Image Viewer"
                                         ToolTipDescription="" />
                    </r:RibbonApplicationMenu.Command>
                    <r:RibbonApplicationMenuItem Command="{StaticResource OpenCommand}" />
                    <r:RibbonApplicationMenuItem Command="{StaticResource ResumeReadingKey}" />
                    <Separator />
                    <r:RibbonApplicationMenuItem Name="ramiPreviousArchive" Command="{StaticResource PreviousArchive}" />
                    <r:RibbonApplicationMenuItem Name="ramiNextArchive" Command="{StaticResource NextArchive}" />
                    <r:RibbonApplicationMenuItem Command="{StaticResource GotoPageCommand}"  />
                    
                </r:RibbonApplicationMenu>
              
            </r:Ribbon.ApplicationMenu>
            <!-- Quick pick menu -->
            <r:Ribbon.QuickAccessToolBar>
                <r:RibbonQuickAccessToolBar CanUserCustomize="True" >
                    <r:RibbonButton Command="{StaticResource OpenCommand}" r:RibbonQuickAccessToolBar.Placement="InToolBar" />
                    <r:RibbonButton Command="{StaticResource ResumeReadingKey}" r:RibbonQuickAccessToolBar.Placement="InCustomizeMenuAndToolBar" />
                    <r:RibbonButton Command="{StaticResource PreviousArchive}" r:RibbonQuickAccessToolBar.Placement="InCustomizeMenuAndToolBar" />
                    <r:RibbonButton Command="{StaticResource NextArchive}" r:RibbonQuickAccessToolBar.Placement="InCustomizeMenuAndToolBar" />
                   
                </r:RibbonQuickAccessToolBar>
            </r:Ribbon.QuickAccessToolBar>
            
        </r:Ribbon>
        <StatusBar DockPanel.Dock="Bottom" >
            <Label x:Name="lblPageNumber" MaxWidth="40" MinWidth="40" Width="40" />
            <Separator></Separator>
            <Label x:Name="lblPageName" />            
        </StatusBar> 
        <Border Margin="4,2,5,2" Padding="8" Background="#7D8E8F"  DockPanel.Dock="Right"  CornerRadius="8,8,8,8">
            <ListBox Style="{StaticResource PageListBoxStyle}" SelectionChanged="comicPage_SelectionChanged" 
                     Margin="6,6,6,0" VerticalAlignment="Top"  IsSynchronizedWithCurrentItem="True" 
                     ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                     SelectionMode="Single" 
                     AllowDrop="True" Visibility="Visible" Name="lstPages"
                     MouseWheel="page_MouseWheel" 
                    >
                <ListBox.ItemTemplate>
                    <DataTemplate  DataType="{x:Type local:comicPage}">
                        <Grid Margin="6" Visibility="Visible">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="60" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Label Grid.Row="2" Content="{Binding Path=FileName, FallbackValue=Test}" Visibility="Collapsed"   />
                            <Image x:Name="imgPage" HorizontalAlignment="Center" Height="60" Grid.Row="0" 
                                   Source="{Binding Path=FileNameUri}" RenderTransformOrigin="0.5,0.5"
                                   VerticalAlignment="Bottom">
                                <Image.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform ScaleX="1" ScaleY="1"/>
                                        <SkewTransform AngleX="0" AngleY="0"/>
                                        <RotateTransform Angle="0"/>
                                        <TranslateTransform X="0" Y="0"/>
                                    </TransformGroup>
                                </Image.RenderTransform>
                                <Image.ToolTip>
                                    <ToolTip Style="{DynamicResource TransparentToolTipStyle}">
                                        <ContentControl Content="{Binding Path=FileName}" />
                                    </ToolTip>
                                </Image.ToolTip>
                            </Image>
                            <Rectangle HorizontalAlignment="Stretch" Margin="0,1,0,0" x:Name="rectReflection" Width="Auto" Grid.Row="1" Height="30">
                                <Rectangle.Fill>
                                    <VisualBrush Stretch="None" AlignmentX="Center" AlignmentY="Top"
						                         Visual="{Binding ElementName=imgPage}">
                                        <VisualBrush.RelativeTransform>
                                            <TransformGroup>
                                                <MatrixTransform Matrix="1,0,0,-1,0,0" />
                                                <TranslateTransform Y="1" />
                                                <ScaleTransform ScaleX="1" ScaleY="-1" CenterX="0.5" CenterY="0.5"/>
                                            </TransformGroup>
                                        </VisualBrush.RelativeTransform>
                                    </VisualBrush>
                                </Rectangle.Fill>
                                <Rectangle.OpacityMask>
                                    <RadialGradientBrush GradientOrigin="0.5,1.041">
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.202" ScaleY="2.865"/>
                                                <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
                                                <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
                                                <TranslateTransform X="-0.002" Y="-0.491"/>
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Color="#FF000000" Offset="0"/>
                                        <GradientStop Color="#00000000" Offset="0.8"/>
                                    </RadialGradientBrush>
                                </Rectangle.OpacityMask>
                            </Rectangle>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBox.Background>
                    <LinearGradientBrush EndPoint="0.466,0.06" StartPoint="0.465,0.877">
                        <GradientStop Color="#BFBFBF" Offset="0"/>
                        <GradientStop Color="#1D252F" Offset="1"/>
                    </LinearGradientBrush>
                </ListBox.Background>
            </ListBox>
        </Border>
        <DockPanel>
            <wpe:ZoomControl x:Name="ZoomControl" >
                <wpe:ZoomControl.Resources>
                    <Style TargetType="{x:Type Rectangle}">
                        <Setter Property="extbehaviour:DragBehaviour.IsDragEnabled" Value="True" />
                        <Setter Property="extbehaviour:DragBehaviour.OnlyIn"  Value="True" />
                        <Setter Property="extbehaviour:DragBehaviour.X"
                                Value="{Binding RelativeSource={RelativeSource Self},Path=(Image.Left)}" />
                        <Setter Property="extbehaviour:DragBehaviour.Y"
                                Value="{Binding RelativeSource={RelativeSource Self},Path=(Image.Top)}" />
                    </Style>
                </wpe:ZoomControl.Resources>
                
                  
                        <Image x:Name="imgFull" Source="{Binding FileNameUri}" 
                               Stretch="Uniform" StretchDirection="Both"  />

             
            </wpe:ZoomControl> 
        </DockPanel>
    </DockPanel>
</r:RibbonWindow>
